// miniprogram/pages/cjyy/cjyy.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    theList: ''
  },
  getPhoneNumber(e) {
    var _ = this;
    var area = _.data.area;
    var agent = _.data.agent;
    console.log(e)
    if (e.detail.errMsg == 'getPhoneNumber:fail user deny') { //用户点击了拒绝
      _.hideModal();
    } else { //允许授权执行跳转
      wx.request({
        url: "https://zg99.offcn.com/index/wechat/getwxphone?actid=50866&callback=?", //手机号解密
        data: {
          code: e.detail.code
        },
        success(res) {
          console.log('res', res.data);
          if (res.data.status == 1) {
            var phone = res.data.phone; //获取得到手机号
            console.log("手机号=", phone)
            wx.setStorageSync('jmmdphone', phone)
            wx.request({ //发送请求
              url: "https://zg99.offcn.com/index/chaxun/register/?actid=50866&callback=?",
              data: {
                phone: phone,
                dishi: _.data.dishi,
                time: _.data.time,
                isagree: true,
                area: area,
                agent: agent
              }, //接收参数 
              success(res) { //返回
                var jsonStr = res.data;
                jsonStr = jsonStr.replace("(", "");
                jsonStr = jsonStr.replace(")", "");
                if (typeof jsonStr != 'object') {
                  jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                  var theJson = JSON.parse(jsonStr);
                };
                console.log(theJson)
                wx.request({
                  url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
                  method: 'POST',
                  data: {
                    activeId: 32,
                    mobile: phone,
                    areaCode: _.data.area,
                    agent: _.data.agent,
                    pageId: _.data.page
                  },
                })
                _.setData({
                  fixed:!1
                })
              }
            })
          } else {
            console.log("获取手机号失败 ", res.data.msg)
          }
        }
      })
    }
  },
  xxx() {
    wx.showToast({
      title: '请填写完整信息！',
      icon: 'none'
    })
  },
  submit() {
    const _ = this;
    var phone = wx.getStorageSync('jmmdphone')
    if(phone){
      wx.request({ //发送请求
        url: "https://zg99.offcn.com/index/chaxun/getlist/?actid=50866&callback=?",
        data: {
          phone: phone,
          dishi: _.data.dishi,
          time: _.data.time,
          limits: '100'
        }, //接收参数
        success(res) { //返回
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          };
          console.log(theJson)
          _.setData({
            theList: theJson.lists
          })
          console.log(_.data.theList)
        }
      })
   
    } else  {
      wx.showToast({
        title: '请先登录！',
        icon:'none'
      })
      _.setData({
        fixed:1
      })
    }
    
   
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _ = this;
    console.log(options);
    _.setData({
      area: options.area,
      agent: options.agent
    })
    if (options.page) {
      _.setData({
        page: options.page
      })
    }
  },
 
  //点击选择-省份地市
  choisedishi() {
    var _ = this;
    _.setData({
      binddishi: 1,
    })
  },
  //点击选择-省份地市
  choisetime() {
    var _ = this;
    var dishi = _.data.dishi
    if(dishi){
      _.setData({
        bindtime: 1,
      })
    } else {
      wx.showToast({
        title: '请先选择地市！',
        icon:'none'
      })
    }
    
  },
  //一级联动-省份
  dishi() {
    var _ = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=50866&callback=?', //接收url
      data: {
        level: '1',
        dishi: ''
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
          console.log(theJson)
        }
        // console.log(theJson)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].dishi)
        }
        // console.log(list)
        _.setData({
          dishiList: list
        });
      }
    })
  },
  //报考岗位
  time() {
    var _ = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=50866&callback=?', //接收url
      data: {
        level: '2',
        grfiled: 'dishi',
        grtext: _.data.dishi
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
          console.log(theJson)
        }
        // console.log(theJson)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].time)
        }
        // console.log(list)
        _.setData({
          timeList: list
        });
      }
    })
  },
  //点击选择-地市 
  setdishi(e) {
    var _ = this;
    console.log(e.currentTarget.dataset.dishi)
    _.setData({
      dishi: e.currentTarget.dataset.dishi,
      binddishi: !1
    })

  },
  //点击选择-年份
  settime(e) {
    var _ = this;
    console.log(e.currentTarget.dataset.time)
    _.setData({
      time: e.currentTarget.dataset.time,
      bindtime: !1
    })

  },
  //点击重新选择-地市
  rechoisedishi() {
    var _ = this;
    _.setData({
      danweiList: !1,
      danwei: !1
    })
  },
  //点击重新选择-报考岗位
  rechoisetime() {
    var _ = this;
    _.setData({
      danweiList: !1,
      danwei: !1
    })
  },

  closeselect() {
    var _ = this;
    _.setData({
      binddishi: !1,
      bindtime: !1,
      bindbianma: !1,
      binddanwei: !1
    })
  },
  close(){
    var _ = this;
    _.setData({
      theList: !1,
    })
  },
  
  xy: function (e) {
    var _ = this;
    wx.redirectTo({
      url: '../agreement/agreement',
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})